<% 
@servlet.getResponse().setStatus(400);

var message = @ObjectUtils.toString(@request.getAttribute('message'));

if (isBlank(message)){
	var ex = @ExceptionUtils.getThrowable(request);
	if (ex != null){
		if(@StringUtils.startsWith(@ex.getMessage(), 'msg:')){
			message = @StringUtils.replace(@ex.getMessage(), 'msg:', '');
		}else if (ex.class.name == 'org.springframework.validation.BindException'){
			for (var e in ex.globalErrors){
				message = message + '@@' + e.defaultMessage + '(' + e.objectName + ')<br/>';
			}
			for (var e in ex.fieldErrors){
				message = message + '@@' + e.defaultMessage + '(' + e.field + ')<br/>';
			}
		}else if (ex.class.name == 'javax.validation.ConstraintViolationException'){
			for (var v in ex.constraintViolations) {
				message = message + '@@' + v.message + '(' + v.propertyPath + ')<br/>';
			}
		}else{
			message = message + ex.message;
		}
		@org.slf4j.LoggerFactory.getLogger('error/400').info(ex.message, ex);
	}
}

if (isBlank(message)){
	message = text('sys.error.400.message');
}

// 如果是异步请求或是手机端，则直接返回信息
if (@Servlets.isAjaxRequest(request)) {
	print(@Servlets.renderResult(@Global.FALSE, message));
}

// 输出异常信息页面
else {
%>
<% layout('/layout/default.html', {title: '400 - '+text('sys.error.400.title'), libs: ['layout']}){ %>
<!-- Main content -->
<section class="content">
	<div class="error-page">
		<h2 class="headline text-yellow"> 400</h2>

		<div class="error-content">
			<h3><i class="fa fa-warning text-yellow"></i> ${text('sys.error.400.title')}</h3>

			<p>
				${message}<a href="${ctx}">返回主页</a>
			</p>

			<form class="search-form">
				<div class="input-group">
					<input type="text" name="search" class="form-control" placeholder="Search">

					<div class="input-group-btn">
						<button type="submit" name="submit" class="btn btn-warning btn-flat"><i class="fa fa-search"></i>
						</button>
					</div>
				</div>
				<!-- /.input-group -->
			</form>
		</div>
		<!-- /.error-content -->
	</div>
	<!-- /.error-page -->
</section>
<!-- /.content -->
<div style="text-align: center;">
	<% var productName = @Global.getProperty('productName'), productVersion = @Global.getProperty('version'); %>
	<strong>Copyright &copy; 2017-${@DateUtils.getYear()} <a href="http://jsite.org.cn">${productName}</a>.</strong> All rights
	reserved.
</div>

<% } %>
<% } %>